package com.taxigang.client.ui;

import com.google.gwt.user.client.Window;
import com.taxigang.client.Session;
import com.taxigang.client.TestMode;

public class LayoutConstants {
	public enum LayoutField{SIGIN, SIGIN_TMP};
	private Session.UserAgent 	userAgent;

	private final static int SMALL_WIDTH = 316; //or 320
	private final static int SMALL_HEIGHT = 416;
	private final static int SMALL_HEIGHT_FB = 340;
	
	
//	private final static int LARGE_WIDTH = 1600;
//	private final static int LARGE_HEIGHT = 1000;
	private final static int LARGE_WIDTH = getClientWidth();
	private final static int LARGE_HEIGHT = 900;
	
	private final static int FB_WIDTH = 744;
	private final static int FB_HEIGHT = 760;
	
	
	private final static int DECORATED_BORDERWIDTH =6;
	private LayoutConstants(){
	}
	private static LayoutConstants  instance = new LayoutConstants();
	public static LayoutConstants getInstance() { return instance; }
	public void setSession(Session session){
		this.userAgent = session.getUserAgent();
	}

	private static int getClientWidth(){
		if (TestMode.testing){
			return 0;
		} else {
			return Window.getClientWidth();
		}
	}
	public int getWindowWidth(){
		int value = SMALL_WIDTH;
		switch (userAgent){
		case IPHONE:
			value = SMALL_WIDTH;
			break;
		case PC:
		case PC_WEBKIT:
			value = LARGE_WIDTH;
			if (value==0){
				value = 1920;
			}
			break;
		case FB_WEBKIT:
		case FB:
			value = FB_WIDTH;
			break;
		}
		if (value==0){
			Window.alert("width="+value);
		}
		return value;
	}
	
	
	public int getX1(){		
		int value = 100;
		switch (userAgent){
			case IPHONE:
				value = 0;
				break;
			case FB:
				value = 50;			
				break;
			}
		return value;
	}
	
	public int getLoadingX(){		
		int value = 100;
		switch (userAgent){
			case IPHONE:
				
				break;
			case FB:
				value = FB_WIDTH/2;			
				break;
			}
		return value;
	}
	public int getX2(){		
		int value = LayoutConstants.getInstance().getWindowWidth() -350;
		switch (userAgent){
			case IPHONE:
				
				break;
			case FB:
				break;
			}
		return value;
	}
	
	
	public int getLoadingY(){		
		int value = 50;
		switch (userAgent){
			case IPHONE:
				
				break;
			case FB:
				value = FB_HEIGHT/2;			
				break;
			}
		return value;
	}
	
	public int getY1(){		
		int value = 50;
		switch (userAgent){
			case IPHONE:
				value = 0;
				break;
			case FB:
				value = 60;			
				break;
			}
		return value;
	}
	
	public int getY2(){		
		int value = getY1()+SMALL_HEIGHT+50;
		switch (userAgent){
		case IPHONE:
			
			break;
		case FB:
		case FB_WEBKIT:
			value = getY1()+SMALL_HEIGHT_FB+10;			
			break;
		}
		return value;
	}
	
	
	public int getWindowHeight(){
		int value = SMALL_HEIGHT;
		switch (userAgent){
		case IPHONE:
			//value = ;
			break;
		case PC:
		case PC_WEBKIT:
			value = LARGE_HEIGHT;
			break;
		case FB_WEBKIT:
		case FB:
			value = FB_HEIGHT;
			break;
		}
		return value;


	}
	
	public int getSearchPanelWidth(){
		int value =0;
		switch (userAgent){
		case IPHONE:
			value = getWindowWidth();
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = SMALL_WIDTH;
			break;
		}
		return value;


	}
	
	public int getSearchPanelHeight(){
		int value = getWindowWidth();;
		switch (userAgent){
		case IPHONE:			
			break;
		case PC:
		case PC_WEBKIT:
			value = SMALL_HEIGHT;
			break;
		case FB_WEBKIT:
		case FB:
			value = SMALL_HEIGHT_FB;
			break;
		}
		return value;


	}
	
	public int getSearchContentHeight(){
		int value = getWindowHeight() - getButtonPanelHeight() - getTitlePanelHeight();
		switch (userAgent){
		case IPHONE:
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = getSearchPanelHeight() - getButtonPanelHeight() - getTitlePanelHeight();
			break;
		}
		return value;
	}

	public int getNewMessageContentHeight(){
		int value = getWindowHeight() - getButtonPanelHeight() - getTitlePanelHeight();
		switch (userAgent){
		case IPHONE:
			break;
		case PC:
		case PC_WEBKIT:
			value = SMALL_HEIGHT - getButtonPanelHeight() - getTitlePanelHeight();
			break;
		case FB_WEBKIT:
		case FB:
			value = SMALL_HEIGHT_FB - getButtonPanelHeight() - getTitlePanelHeight();
			break;
		}
		return value;
	}

	
	public int getMyTaxiGangsPanelWidth(){
		int value =0;
		switch (userAgent){
		case IPHONE:
			value = getWindowWidth();
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = SMALL_WIDTH;
			break;
		}
		return value;


	}
	
	public int getMyTaxiGangsPanelHeight(){
		int value = getWindowHeight();
		switch (userAgent){
		case IPHONE:			
			break;
		case PC:
		case PC_WEBKIT:
			value = SMALL_HEIGHT;
			break;
		case FB_WEBKIT:
		case FB:
			value = SMALL_HEIGHT_FB;
			break;
		}
		return value;


	}
	
	public int getMyTaxiGangsContentHeight(){
		int value = getContentHeight();
		switch (userAgent){
		case IPHONE:			
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = getMyTaxiGangsPanelHeight() - getButtonPanelHeight() - getTitlePanelHeight();
			break;
		}
		return value;


	}
	
	public int getMessagePanelWidth(){
		int value = getWindowWidth();
		switch (userAgent){
		case IPHONE:
			//
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = SMALL_WIDTH;
			break;
		}
		return value;


	}
	public int getMessagePanelHeight(){
		int value = getWindowHeight();
		switch (userAgent){
		case IPHONE:			
			break;
		case PC:
		case PC_WEBKIT:
			value = SMALL_HEIGHT;
			break;
		case FB_WEBKIT:
		case FB:
			value = SMALL_HEIGHT_FB;
			break;
		}
		return value;


	}
	
	public int getMessageContentHeight(){
		int value = getContentHeight();
		switch (userAgent){
		case IPHONE:			
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = getMyTaxiGangsPanelHeight() - getButtonPanelHeight() - getTitlePanelHeight();
			break;
		}
		return value;


	}
	


	public int getFeedbackPanelWidth(){
		int value =0;
		switch (userAgent){
		case IPHONE:
			value = getWindowWidth();
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = SMALL_WIDTH;
			break;
		}
		return value;


	}
	
	public int getFeedbackPanelHeight(){
		int value = getWindowHeight();
		switch (userAgent){
		case IPHONE:			
			break;
		case PC:
		case PC_WEBKIT:
			value = SMALL_HEIGHT;
			break;
		case FB_WEBKIT:
		case FB:
			value = SMALL_HEIGHT_FB;
			break;
		}
		return value;


	}
	
	
	public int getHomePanelWidth(){
		int value = getWindowWidth();
		switch (userAgent){
		case IPHONE:
			//
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = SMALL_WIDTH;
			break;
		}
		return value;


	}
	
	
	
	

	public int getButtonPanelHeight(){
		int value = 70;
		switch (userAgent){
		case IPHONE:
			//value = 40;
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = 70;
			break;
		}
		return value;


	}

	public int getMapButtonPanelHeight(){
		int value = getButtonPanelHeight();
		switch (userAgent){
		case IPHONE:
			//value = ;
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			value = 0;
			break;
		}
		return value;


	}

	public int getTitlePanelHeight(){
		int value = 40;
		switch (userAgent){
		case IPHONE:
			value = 40;
			break;
		}
		return value;


	}

	public int getBorderWidth(){
		int value = 6;
		switch (userAgent){
		case IPHONE:
			value = 6;
			break;
		}
		return value;


	}

	public int getHomeMainWindowHeight(){
		int value = LayoutConstants.getInstance().getWindowHeight()-LayoutConstants.getInstance().getTitlePanelHeight() - 4 * LayoutConstants.getInstance().getBorderWidth();
		value -= getHomeAdditionalWindowHeight();
		switch (userAgent){
		case IPHONE:
			//value = 6;
			break;
		}
		return value;


	}

	public int getHomeAdditionalWindowHeight(){
		int value = 200;
		switch (userAgent){
		case IPHONE:
			//value = 6;
			break;
		}
		return value;


	}

	public int getContentHeight(){
		int value = getWindowHeight() - getButtonPanelHeight() - getTitlePanelHeight();
		return value;
	}


	public int getContentWithoutButtoPanelHeight(){
		int value = getWindowHeight() - getTitlePanelHeight();
		return value;
	}

	public int getHeight(LayoutField field){
		int value = 0;
		switch (userAgent){
		case IPHONE:
			switch(field){
			case SIGIN:
				value = 90;
				break;
			case SIGIN_TMP:
				value = (SMALL_HEIGHT-getTitlePanelHeight() - 20 -4*DECORATED_BORDERWIDTH)/2;
				break;
			}
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			switch(field){
			case SIGIN:
			case SIGIN_TMP:
				value = 200;
				break;
			}
			break;
			
		}
		return value;
	}

	public int getWidth(LayoutField field){
		int value = 0;
		switch (userAgent){
		case IPHONE:
			switch(field){
			case SIGIN:
				value = SMALL_WIDTH -2*DECORATED_BORDERWIDTH;
				break;
			}
			break;
		case PC:
		case PC_WEBKIT:
		case FB_WEBKIT:
		case FB:
			switch(field){
			case SIGIN:
				value = 210;
				break;
			}
			break;
			
		}
		return value;
	}
	public int getFeedbackButtonWidth() {
		// TODO Auto-generated method stub
		return 100;
	}

	public int getFeedbackButtonHeight() {
		// TODO Auto-generated method stub
		return 30;
	}



}

